﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using System.Data;

public partial class Master_Admin_Admore : Admin_BasePage
{
    protected Cutter cut = new Cutter();
    protected void Page_Load(object sender, EventArgs e)
    {

        cut.UpFoler = Admin_UpFolder + "/Ad";
        cut.UpSize = configInfo.UpSize;
        if (!Page.IsPostBack)
        {
            bind();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string Msg = "";
        cut.IsNewFile = true;
        cut.FileType = new string[] { ".jpeg", ".jpg" };
        bool isok = UpLoad_picture.UpSave(FileUpload1, cut, out Msg);
        if (!isok)
        {
            ShowMsgBack(Msg);
            Response.End();
        }
        string Sqlstr = "Insert into IndexTabAd(Pictext,PicTitle) values('" + Msg + "','" + StringHelper.HtmlEncrypt(StringHelper.RemoveHtml(Txt_PicName.Text)) + "')";
        ExcuteSqlTextBLL.ExcuteResult(Sqlstr);
        ResultStr("Admin_Admore.Aspx", "图片添加成功！");
        Response.End();
    }
    protected void bind()
    {
        string Sqlstr = "Select * from IndexTabAd order by addtime desc";
        DataTable dt = ExcuteSqlTextBLL.GetDataTable(Sqlstr);
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
        if (dt.Rows.Count > 6)
        {
            this.btnSubmit.Enabled = false;
            this.btnSubmit.Text = "幻灯图最多只能五张";
            this.btnSubmit.Style.Add("cursor", "none");
        }


    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delinfo")
        {
            try
            {
                DataTable dt = ExcuteSqlTextBLL.GetDataTable("Select * from IndexTabAd where id=" + e.CommandArgument.ToString());
                if (dt.Rows.Count > 0)
                {
                    string picAdd = dt.Rows[0]["pictext"].ToString();
                    string PicUrl = Server.MapPath(configInfo.InstallDir + picAdd);
                    if (System.IO.File.Exists(PicUrl))
                    {
                        FileObj.FileDel(PicUrl);
                    }
                }
                string Sqlstr = "delete From IndexTabAd where id=" + e.CommandArgument.ToString();
                ExcuteSqlTextBLL.ExcuteResult(Sqlstr);

            }
            catch
            {

            }
            Response.Write("<script>alert('删除成功!');location.href='Admin_Admore.Aspx';</script>");
            Response.End();
        }
    }
}
